//
//  YXForumToolbarView.m
//  CreditCard
//
//  Created by 杨旭 on 2017/12/27.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "YXForumToolbarView.h"

@interface YXForumToolbarView ()
@property (nonatomic ,strong) UIButton *leftBtn;
@property (nonatomic ,strong) UIButton *rightBtn;
@property (nonatomic ,strong) UIButton *releaseBtn;
@property (nonatomic ,strong) UIView *lineView;
@end

@implementation YXForumToolbarView

- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _leftBtn.tag = 900;
        [_leftBtn setImage:[UIImage imageNamed:@"置顶"] forState:(UIControlStateNormal)];
        [_leftBtn addTarget:self action:@selector(action:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _leftBtn;
}
- (UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _rightBtn.tag = 901;
        [_rightBtn setImage:[UIImage imageNamed:@"刷新"] forState:(UIControlStateNormal)];
               [_rightBtn addTarget:self action:@selector(action:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _rightBtn;
}

- (UIButton *)releaseBtn {
    if (!_releaseBtn) {
        _releaseBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _releaseBtn.tag = 902;
        [_releaseBtn setImage:[UIImage imageNamed:@"发布"] forState:(UIControlStateNormal)];
        [_releaseBtn addTarget:self action:@selector(action:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _releaseBtn;
}

- (void)action:(UIButton *)sender {
    if (self.clickSelectBtnBlock) {
        self.clickSelectBtnBlock(sender.tag-900,sender);
    }
    
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = color_lineColor;
    }
    return _lineView;
}

-(instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.lineView];
        [self addSubview:self.leftBtn];
        [self addSubview:self.rightBtn];
        [self addSubview:self.releaseBtn];
        
    
    }
    return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
    UIView *view = [super hitTest:point withEvent:event];
    
    if (view == nil) {
        
        for (UIView *subView in self.subviews) {
            
            CGPoint tp = [subView convertPoint:point fromView:self];
            
            if (CGRectContainsPoint(subView.bounds, tp)) {
                
                view = subView;
                
            }
            
        }
        
    }
    
    return view;
    
}


- (void)layoutSubviews {
    [super layoutSubviews];
    YXWeakSelf
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mas_left).offset(0);
        make.top.equalTo(weakSelf.mas_top).offset(0);
        make.size.mas_equalTo(CGSizeMake(kScreenWidth, 1));
    }];
    
    [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.left.equalTo(weakSelf.mas_left).offset(60);
        [_leftBtn sizeToFit];
    }];
    
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.right.equalTo(weakSelf.mas_right).offset(-60);
        [_rightBtn sizeToFit];
    }];
    
    [_releaseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.mas_centerX);
        make.top.equalTo(weakSelf.mas_top).offset(-20);
        [_releaseBtn sizeToFit];
    }];
    

}


@end
